home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / PRINTING.SWG / 0010_PRINTER4.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  5KB  |  141 lines

  1. (*
  2. I am trying to figure out how to trap errors as they occur in my
  3. Program and send messages to the user.. The most common error would be a
  4. failed attempt to print but I don't know how to not stop the Program
  5. when an error occurrs. You see, I don't want to have an {$I-},{$I+}
  6. after every time the Printer prints..
  7.  
  8.  
  9. not having any details of what you are doing, I'll take a stab in the dark.
  10. Have an output routine and pass it a String.  The output routine would take
  11. the String and sent it to the Printer.  ( Since you mentioned Printer, I
  12. assume this is where you wish to send all output.)  Now have an output routine
  13. For the screen.  Ah heck, here's an example. <g>  This is some code I wrote to
  14. output Various things to the Printer.  No doubt some will claim to have better
  15. solutions.  That's fine, but here's mine.  There is a routine you will see
  16. called OUTCON(s : String; CH : Char);  It is a routine to send output to the
  17. screen and inForm the user that there is a problem.  of course that's a
  18. different topic then sending output to the Printer.  Hope this helps.
  19. *)
  20.  
  21. Const
  22.   TimedOut   = $01;  { Used to determine the Type of Printer error }
  23.   IOError    = $08;
  24.   OutofPaper = $20;
  25.   notBusy    = $80;
  26.   TestAll    = TimedOut+IOError+OutofPaper;
  27.   NoUL       = False;
  28.   UL         = True;
  29.  
  30. Var
  31.   PrnStatus : Byte;
  32.  
  33. Function PrinterReady : Boolean;
  34. { checks the status of the Printer and returns True if ready to recieve a Chara
  35. { This Function will return the status of your Printer.  Status      }
  36. { should be interpreted as follows:  (x'90' (d'144') is "Ready"):    }
  37. { $01 = Printer Time-out          $02 = not Used                     }
  38. { $04 = not Used                  $08 = I/O Error                    }
  39. { $10 = Printer Selected          $20 = Out of Paper                 }
  40. { $40 = Acknowledge               $80 = not Busy                     }
  41. Var
  42.    Regs : Registers;
  43.    TempStatus : Byte;
  44. begin
  45.   With Regs Do
  46.     begin
  47.       DX := 0;
  48.       AX := $0200;
  49.       Intr($17,Regs);
  50.       PrnStatus := Hi(AX);
  51.       TempStatus := PrnStatus;
  52.       if TempStatus and TestAll = $00 then PrinterReady := True
  53.         else PrinterReady := False;
  54.     end;
  55. end; { Function PrinterReady }
  56.  
  57. Procedure GetPrnError(Var ESC : Boolean);
  58. { gets the error that occured With the Printer and gives the user a chance to }
  59. { correct the problem and continue. }
  60. Var
  61.   CH : Char;
  62. begin
  63.   Repeat
  64.     PrnStatus := PrnStatus and TestAll;
  65.     Case PRnStatus of
  66.       TimedOut   : OutCon('Printer timed out.  Retry??? (Y/N)',CH);
  67.       IOError    : OutCon('An IOError has occured.  Retry??? (Y/N)',CH);
  68.       OutofPaper : OutCon('Printer out of paper.  Retry??? (Y/N)',CH);
  69.     else OutCon('A Print Device Error has occured.  Retry??? (Y/N)',CH);
  70.     end;
  71.     if CH = 'N' then esc := True;
  72.   Until ESC or PrinterReady;
  73. end;
  74.  
  75. Function EscapePushed : Boolean;
  76. { Checks the keyboard buffer For a Character and test to see if it was the   }
  77. { Esc key.  if it was it returns True else it returns False.                 }
  78. Var
  79.   CH : Char;
  80. begin
  81.   if KeyPressed then        { Check the keyboard buffer For a Character }
  82.   begin
  83.     CH := ReadKey;          { if Character then check it }
  84.     CH := UpCase(CH);
  85.     if Ch = Chr(27) then EscapePushed := True
  86.     else EscapePushed := False;
  87.   end
  88.   else EscapePushed := False;
  89. end; { EscapePushed }
  90.  
  91. Procedure ConfirmQuit(Var ESC : Boolean);
  92. { confirms that the user wants to quit printing }
  93. Var
  94.   CH : Char;
  95. begin
  96.   OutCon('Cancel all print jobs? (Y/N)',Ch);
  97.   if CH = 'Y' then ESC := True
  98.     else ESC := False;
  99. end;
  100.  
  101. Procedure FFeed;
  102. { sends a Form feed command to the Printer }
  103. begin
  104.   Write(LST,#12);
  105. end;
  106.  
  107. Procedure PrintCh(CH : Char;
  108.                   Underline : Boolean;
  109.                   Var OK    : Boolean);
  110. { Writes a Single Character to the Printer }
  111. begin
  112.   if UnderLine then {$I-} Write(LST, #27#45#1, CH, #27#45#0) {$I+}
  113.   else {$I-} Write(lst,CH); {$I+}
  114.   if Ioresult <> 0 then OK := False
  115.     else OK := True;
  116. end;
  117.  
  118. Procedure WriteStr(TheStr  : String;
  119.                    Return, UnderLine : Boolean;
  120.                    Var ESC : Boolean);
  121. Var
  122.   PrnReady : Boolean;
  123.   OK       : Boolean;
  124.   I        : Byte;
  125. begin
  126.   Repeat
  127.     PrnReady := PrinterReady
  128.     if not PrnReady then GetPrnError(ESC);
  129.   Until PrnReady or ESC;
  130.   I := 1;
  131.   While PrnReady and not Esc and (I <> Length(theStr)+1) do
  132.   begin
  133.     PrnReady := PrinterReady
  134.     if not PrnReady then GetPrnError(ESC);
  135.     if not ESC then PrintCh(theStr[I],UnderLine,OK);
  136.     if not esc then if EscapePushed then confirmQuit(Esc);
  137.     if OK then Inc(I);
  138.   end;
  139.   if PrnReady and not ESC and RETURN then {$I-} Writeln(LST); {$I+}
  140. end;
  141.